let dateFormat = require('../../utils/util');
import {
  venue
} from '../../api/apiData'
var pageNum1 = 1; //页码

Page({
  data: {
    bookList:[],
    indexB:0,
    loadMoreText: '加载中...', //底部文字
    list: [],
  },
  onLoad: function () {
    venue.bookDateList({},res=>{
       this.setData({
         bookList:res.data,
         book_date:res.data[0].date
       })
    this.getList(1)
    })

  },
  toApply(e){
    let id = e.currentTarget.dataset.id
    let date = this.data.bookList[this.data.indexB].date
    wx.navigateTo({
      url: '/pages/apply/index?id='+id+'&date='+date,
    })
  },
  toActBook(e){
    let i = e.currentTarget.dataset.index
    this.setData({
      indexB:i,
      book_date:this.data.bookList[i].date
    })
    this.onPullDownRefresh()
  },
    // 获取列表
    getList(page) {
      var that = this
      venue.lists({
          page: page,
          size: 20,
          book_date: this.data.book_date,
      }, res => {
          that.setData({
              total: res.data.total
          })
          if (res.data.list.length > 0) {
              that.setData({
                  list: that.data.list.concat(res.data.list) //合并数据
              })
              if (11 > res.data.list.length > 0) {
                  that.setData({
                      loadMoreText: '' //没有更多了
                  })
              }

          } else {
              if (page !== 1) {
                  that.setData({
                      loadMoreText: '暂无数据'
                  })
              } else {
                  that.setData({
                      list: [],
                      loadMoreText: '暂无数据'
                  })
              }
          }
          wx.stopPullDownRefresh();
      })
  },
/**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
      pageNum1 = 1
      this.setData({
          list: [],
      });
      this.getList(1)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
      pageNum1 += 1;
      this.getList(pageNum1)
  },

})